package com.mall.mymall.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.mymall.dao.dto.EmployeeDto;
import com.mall.mymall.dao.dto.QueryDto;
import com.mall.mymall.dao.dto.StoresDto;
import com.mall.mymall.dao.dto.querypage.EmployeePageRequest;
import com.mall.mymall.dao.entity.Employees;
import com.mall.mymall.mapper.EmployeesMapper;
import com.mall.mymall.service.EmployeesService;
import org.springframework.stereotype.Service;

@Service
public class EmployeesServiceImpl extends ServiceImpl<EmployeesMapper, Employees> implements EmployeesService {

/**
 * 分页查询员工信息
 *
 * @param employeePageRequest 员工分页查询请求对象，包含分页信息和查询条件
 * @return 返回一个QueryDto对象，其中包含员工信息列表和总记录数
 *
 * 此方法用于根据提供的分页请求和查询条件，返回经过分页处理的员工信息列表
 * 它通过自定义的Mapper方法实现复杂的分页查询逻辑
 */
@Override
public QueryDto<EmployeeDto> pageEmployees(EmployeePageRequest employeePageRequest) {
    // 创建分页对象
    Page<EmployeeDto> page = new Page<>(employeePageRequest.getPageRequestDto().getPage(), employeePageRequest.getPageRequestDto().getSize());

    // 执行自定义分页查询
    IPage<EmployeeDto> resultPage = this.baseMapper.selectEmployeesPage(page, employeePageRequest.getQuery());

    // 构造返回结果
    QueryDto<EmployeeDto> result = new QueryDto<>();
    result.setTotal((int) resultPage.getTotal());
    result.setRecords(resultPage.getRecords());

    return result;
}

}
